#!/usr/bin/env python

import re
import sys


if len(sys.argv) != 4:
    print "Usage: " + sys.argv[0] + " regex_start regex_end ignore"
    print "    regex_start   Regular expression of the last line of the header comments"
    print "    regex_end     Regular expression of the first line of the tail comments"
    print "    ignore        Ignore 'ignore' lines after the header comments"
    print "All lines between the first one matching regex_start and the first one matching regex_end will be printed."
    sys.exit(1)

start = False
ignored = 0
try:
    ignore = int(sys.argv[3])
    if ignore < 0:
        print "'ignore' must be positive!"
        sys.exit(1)
except:
    print "'ignore' must be a integer number"
    sys.exit(1)
    
while True:
    line = sys.stdin.readline()
    if line == '':
        break
    if not start:
        if re.search(sys.argv[1], line) != None:
            start = True
    else:
        if ignored < ignore:
            ignored += 1
            continue
        
        if re.search(sys.argv[2], line) != None:
            break
        else:
            print line[:-1]

sys.exit(0)
